/// 路由规则：flutter_page://path?key1=value1&ke2=value2 其中value需要做urlencode
class SchemeUtil {
  static final String _FLUTTER_SCHEME = "flutter_page";
  static final String _SUFFIX_SCHEME = "://";
  static final String _PARAMS = "?";

  static String getScheme(String actionUrl) {
    if (actionUrl?.isEmpty == true) return actionUrl;
    return Uri.parse(actionUrl).scheme;
  }

  static String getPath(String actionUrl) {
    if (actionUrl?.isEmpty == true) return null;
    var indexScheme = actionUrl.indexOf("://");
    var indexParams = actionUrl.indexOf("?");
    if (indexScheme != -1) {
      return actionUrl.substring(indexScheme + _SUFFIX_SCHEME.length,
          indexParams == -1 ? actionUrl.length : indexParams);
    }
    return null;
  }

  static Map<String, dynamic> getQueryParameter(String actionUrl) {
    return Uri.parse(actionUrl).queryParameters;
  }
}
